<%--
  Created by IntelliJ IDEA.
  User: 494418174
  Date: 2020/3/5 0005
  Time: 14:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="identity" id="identity" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <button type="button"
                    class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm"
                    lay-submit lay-filter="formDemo" style="margin-top: 4px">查询
            </button>
            <button type="reset"
                    class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm"
                    style="margin-top: 4px">重置
            </button>
        </div>
    </div>

</form>

<!-- 搜索条件结束 -->
<%--大图弹出框--%>
<div id="viewDiv" style="display: none;text-align: center">
    <img alt="汽车图片" width="700px" height="320px" id="view_car">
</div>
<table id="carTable" lay-filter="carTable"></table>


<script id="barCar" type="text/html">
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">出租车辆</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="showImg">查看大图</a>
</script>


<!-- 添加和修改的弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form layui-row layui-col-space10" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">起租时间:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="beginDate" id="beginDate" autocomplete="off" class="layui-input"
                               lay-verify="required"
                               placeholder="请输入租车时间" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">换车时间:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="returnDate" id="returnDate" autocomplete="off" class="layui-input"
                               placeholder="请输入换车时间" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
            </div>

            <div class="layui-form-item magb0">
                <label class="layui-form-label">出租单号:</label>
                <div class="layui-input-block" style="padding: 5px">
                    <input type="text" name="rentId" autocomplete="off" class="layui-input"
                           placeholder="请输入出租单号" style="height: 30px;border-radius: 10px">
                </div>
            </div>

            <div class="layui-form-item magb0">
                <label class="layui-form-label">身份证号:</label>
                <div class="layui-input-block" style="padding: 5px">
                    <input type="text" name="identity" id="identity1" autocomplete="off" class="layui-input"
                           placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">车牌号:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="carNumber" class="layui-input" lay-verify="required"
                               placeholder="请输入车牌号" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出租价格:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="price" class="layui-input" lay-verify="required|number"
                               placeholder="请输入车辆出租价格" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
            </div>

            <div class="layui-form-item magb0">
                <label class="layui-form-label">操作员:</label>
                <div class="layui-input-block" style="padding: 5px">
                    <input type="text" name="openName" autocomplete="off" class="layui-input"
                           placeholder="请输入操作员" style="height: 30px;border-radius: 10px">
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                    <button type="button"
                            class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                            lay-filter="doSubmit" lay-submit="">提交
                    </button>
                    <button type="reset"
                            class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">
                        重置
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>
<%-- 添加或者修改弹出框结束 --%>

<script src="/layui/layui.js"></script>
<script>
    var carTable
    var index
    var url
    var uploadImg
    layui.extend({
        dtree: '/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['table','form','layer','jquery','dtree','upload','laydate'], function() {
        var table = layui.table
        var form = layui.form
        var layer = layui.layer
        var $ = layui.jquery
        var laydate=layui.laydate
        // 初始table
        function initCarTable(){
            carTable = table.render({
                elem: "#carTable"
                , url: "/car/findCar?isrenting=0"
                , page: {limit: 5, limits: [5, 10, 15]}
                , cellMinWidth: 80
                , cols: [[ //表头
                    {field: 'carNumber', title: '车牌号', fixed: 'center'}
                    , {field: 'carType', title: '车辆类型', fixed: 'center'}
                    , {field: 'color', title: '车辆颜色', fixed: 'center'}
                    , {field: 'price', title: '车辆价格', fixed: 'center'}
                    , {field: 'rentPrice', title: '出租价格', fixed: 'center'}
                    , {field: 'deposit', title: '出租押金', fixed: 'center'}
                    , {field: 'description', title: '车辆描述', fixed: 'center'}
                    , {field: 'carimg', title: '图片', fixed: 'center',hide:true}
                    , {field: 'createTime', title: '入库时间', fixed: 'center'}
                    , {fixed: 'right', title: '操作', toolbar: '#barCar', width: 250}
                ]]
            })
        }
        //监听行工具事件
        table.on('tool(carTable)', function(obj){
            var data = obj.data
            if(obj.event == "edit"){ // 汽车出租
                carRent(data)
            }else if(obj.event == "showImg"){
                showCarImage(data)
            }
        })
        // 查询
        form.on("submit(formDemo)", function (data) {
            $.post("/rent/findCustomerById",{"identity":$("#identity").val()},function (r) {
                if(r.code==0){
                    initCarTable()
                }else {
                    $("[lay-id=\"carTable\"]").addClass("layui-hide")
                    layer.msg(r.msg)
                }
            })
            return false;
            })


        // form表达提交 -- 新增/修改
        form.on("submit(doSubmit)",function() {
            layer.confirm("您确定要提交该数据么",function(ind){
                $.post("/rent/addRent",$("#dataFrm").serialize(),function(data) {
                    layer.msg(data.msg)
                    layer.close(index)
                    // 刷新table数据
                    carTable.reload()
                })
                layer.close(ind)
            })
            return false;
        })
        //显示大图
        function showCarImage(data) {
            layer.open({
                type:1
                ,title:data.carNumber+"的图片"
                ,content:$("#viewDiv")
                ,area:['750px','380px']
                ,success:function (index) {
                    $("#view_car").attr("src",data.carimg)
                }
            })
        }
        function carRent(data) {
            // 弹出框
            index =  layer.open({
                type:1 // 1（页面层）
                , title:"汽车出租"
                , content:$("#saveOrUpdateDiv")
                , area : ['720px', '480px']
                , success:function() {

                    // 查询后台获取出租单号和当前操作人
                    $.post("/rent/getRentNo",function (r) {
                        $("[name=\"rentId\"]").val(r.data.rentId)
                        $("[name=\"openName\"]").val(r.data.openName)
                    })

                    // 给弹出层设置值
                    $("#identity1").val($("#identity").val())
                    $("[name='carNumber']").val(data.carNumber)
                    $("[name='price']").val(data.rentPrice)

                    // 初始化时间
                    laydate.render({
                        elem: '#beginDate' //指定元素
                        ,type : "datetime"
                        ,value:new Date()
                    });

                    laydate.render({
                        elem: '#returnDate' //指定元素
                        , type:"datetime"
                    });


                }
            })
        }

    })

</script>
</body>
</html>
